package com.j.lemon.learn.thread;

import java.util.Vector;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author lijunjun
 * @Date 2019-03-19 16:41
 * @Description
 */
public class VectorUnSafe {
    private static ExecutorService executorService = Executors.newFixedThreadPool(10);

    private static final Vector<String> vector = new Vector<>();

    static {

        for (int i = 0; i < 1000; i++) {
            vector.add(String.valueOf(i));
        }

    }

    private static void iterator() throws InterruptedException {
        int size = vector.size();
        for (int i = 0; i < size; i++) {
            vector.get(i);
            Thread.sleep(10);
        }
    }



    static class MyTest implements Runnable {

        @Override
        public void run() {
            try {
                iterator();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new MyTest());
        t1.start();
        Thread.sleep(50);
        vector.remove(999);
        vector.remove(998);


//        Vector<String> v = new Vector<>();
//        v.add("1");
//        v.add("2");
//        v.add("3");
//        v.add("4");
//        v.add("5");
//        v.add("6");
//        v.add("7");
//        v.remove(0);
//
//        for (String s : v){
//            System.out.println(s);
//        }



    }
}
